home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 578 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.0 KB

  1. Path: solon.com!not-for-mail
  2. From: gordon@sneaky.lerctr.org (Gordon Burditt)
  3. Newsgroups: comp.lang.c.moderated,comp.std.c
  4. Subject: Re: 'h' modifier in printf
  5. Date: 16 Mar 1996 10:21:26 -0600
  6. Organization: What organization?
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4iepq6$af6@solutions.solon.com>
  10. References: <4i801c$455@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. >The "h" modifier says the corresponding argument will be printed as a
  14. >short or unsigned short.
  15. >
  16. >So, given:
  17. >
  18. >short s;
  19. >printf("%d", s);
  20. >printf("%hd", s);
  21.  
  22. >Can these two ever be different?  
  23.  
  24. I don't think so, BUT:
  25. short s = -1;
  26. printf("%x\n", (unsigned int) s);
  27. printf("%hx\n", (unsigned int) s);
  28.  
  29. /* is it allowed to leave out the casts? */
  30.  
  31. prints, on a machine with 16-bit shorts and 32-bit ints:
  32.  
  33. ffffffff
  34. ffff
  35.  
  36. I believe this behavior in FreeBSD's gcc is correct, or at least allowed,
  37. behavior for the given machine architecture.  The h modifier isn't
  38. totally useless, just mostly so.
  39.  
  40.                     Gordon L. Burditt
  41.                     sneaky.lerctr.org!gordon
  42.